﻿<UserControl x:Class="FileUpload_5.FileRowControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:classes="clr-namespace:FileUpload_5.Classes"
    xmlns:local="clr-namespace:FileUpload_5;assembly=FileUpload_5"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
	<UserControl.Resources>
		<classes:ByteConverter x:Key="ByteConverter" />
		<local:FileStateConverter x:Key="FileStateConverter" />

		<Storyboard x:Name="sbProgress">
			<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(RangeBase.Value)">
				<SplineDoubleKeyFrame x:Name="sbProgressFrame" KeyTime="00:00:00.5000000" Value="10"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>

	</UserControl.Resources>
	<Grid x:Name="LayoutRoot">
		<vsm:VisualStateManager.VisualStateGroups>
			<vsm:VisualStateGroup x:Name="UploadStates">
				<vsm:VisualState x:Name="Pending">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="PauseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</vsm:VisualState>
				<vsm:VisualState x:Name="Uploading">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="PauseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</vsm:VisualState>
				<vsm:VisualState x:Name="Deleted">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="PauseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</vsm:VisualState>
				<vsm:VisualState x:Name="Error">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="PauseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</vsm:VisualState>
				<vsm:VisualState x:Name="Finished">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00.2000000">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="PauseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</vsm:VisualState>
				<vsm:VisualState x:Name="Processing">
					<Storyboard>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StateTextBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PercentageProgress" Storyboard.TargetProperty="(UIElement.Opacity)">
							<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="PauseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
							<DiscreteObjectKeyFrame KeyTime="00:00:00">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</vsm:VisualState>
			</vsm:VisualStateGroup>
		</vsm:VisualStateManager.VisualStateGroups>

		<!--Style="{StaticResource BorderStyle}"-->
		<Border BorderBrush="#FFF0F0F0" BorderThickness="0, 0, 0, 1" Padding="2">
			<StackPanel>
				<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Background="White">
					<TextBlock x:Name="FileNameTextBlock" Text="{Binding FileName}" Width="250" Margin="5,0,10,0"  />
					<TextBlock x:Name="FileSizeTextBlock" Text="{Binding FileSize, Converter={StaticResource ByteConverter}}" Width="60" TextAlignment="Right" Margin="0,0,5,0" />
					<TextBlock  Text="{Binding BytesUploaded}" Width="60" TextAlignment="Right" Visibility="Collapsed"/>
					<TextBlock x:Name="StateTextBlock" Text="{Binding State, Converter={StaticResource FileStateConverter}}" Width="60"/>
					<ProgressBar x:Name="PercentageProgress" Width="60" Value="{Binding Percentage}" Style="{StaticResource ProgressBarStyle}"></ProgressBar>
					<StackPanel x:Name="ValidUploadIcon" Width="30" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed">
						<Image Source="Img/tick.png" Height="15"></Image>
					</StackPanel>
					<TextBlock Text="{Binding Percentage}" Width="20" TextAlignment="Right" Visibility="Collapsed" />

					<Button x:Name="DeleteButton" Style="{StaticResource ImageButtonStyle}" Content="Img/cancel.png" Height="15" Click="DeleteButton_Click" ToolTipService.ToolTip="删除" Margin="5,0,0,0" />
					<Button x:Name="PauseButton" Style="{StaticResource ImageButtonStyle}" Content="Img/pause.png" Height="15" Click="PauseButton_Click" ToolTipService.ToolTip="暂停" Margin="5,0,0,0" />
				</StackPanel>
				<TextBlock Foreground="Red" x:Name="ErrorMsgTextBlock" Visibility="Collapsed">上传失败.</TextBlock>
			</StackPanel>
		</Border>

	</Grid>
</UserControl>
